// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境

const db = cloud.database()
const _ = db.command
const todos = db.collection('index_data')

// 云函数入口函数
exports.main = async (event, context) => {
  const slideShow = await todos.where({
    sort: _.eq('slide_show')
  }).orderBy('id', 'asc').get()

  const business = await todos.where({
    sort: _.eq('business')
  }).get()

  const cameraman = await todos.where({
    sort: _.eq('cameraman')
  }).orderBy('id', 'asc').get()

  const recommend = await todos.where({
    sort: _.eq('recommend')
  }).orderBy('id', 'asc').get()

  const hotSale = await todos.where({
    sort: _.eq('hot_sale')
  }).orderBy('id', 'asc').get()

  return {slideShow, cameraman, business, hotSale, recommend}
  
}